package com.javaweb.demo.servlet;

import com.javaweb.demo.dao.UserDao;
import com.javaweb.demo.dao.UserDaolmpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DelfriendServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String username = request.getParameter("username");
        String name = request.getParameter("name");
        request.setAttribute("xiaoxi", "欢迎用户" + username);//request放置信息
        request.setAttribute("username", username);
        UserDao ud = new UserDaolmpl();
        if (ud.delfriend(username,name)) {
            System.out.println("succeed deleting friend!");
            request.getRequestDispatcher("/success.jsp").forward(request,response);
        } else {
            request.getRequestDispatcher("/failtofriend.jsp").forward(request, response);
        }
    }
}
